import React,{Component,View,StyleSheet,Text} from 'react-native';
import FontIcon from 'react-native-vector-icons/FontAwesome';

import {bindActionCreators} from 'redux';
import * as mainScreenActions from '../../actions/mainScreenActions';
import { connect } from 'react-redux';

class topbar extends Component {
  static propTypes = {
    name: React.PropTypes.string,
  };

  constructor(props) {
    super(props);
  }
  popNavigator=()=>{
    this.props.navigator.pop();
  };
  jumptoSet=()=>{
    this.props.navigator.push({
    name: 'bwSet'
    })
  };
  render() {
    return (
      <View style={styles.topbar} >
        {/*返回图标*/}
      	<Text style={styles.icon} onPress={this.popNavigator}>
          <FontIcon name="arrow-left" size={25} color="white" />
        </Text>
        {/*中间部分文字*/}
        <View style={styles.title}>
          <Text style={styles.textfarm}>{/*高村猪场/一线分娩2*/}{this.props.currentUnit}</Text>
          <Text style={styles.textmac}>机器号:{this.props.currentAddr}</Text>
        </View>
        <Text style={styles.icon}/*占位用*/>
          
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  topbar:{
  	flex:2,
  	backgroundColor:"#113477",
    flexDirection:'row',
    justifyContent:'space-around',
    alignItems:"center",
    //安卓的shadow 效果只在5.0以上有效
    elevation:2
  },
  icon:{
    //backgroundColor:'red',
    flex:2,
    justifyContent:'center',
    alignItems:"center",
    textAlign:'center'
  },
  title:{
    flex:10,
    justifyContent:'center',
    //backgroundColor:'yellow'
  },
  textfarm:{
    textAlign:"center",
    color:'white'
  },
  textmac:{
    textAlign:"center",
    color:'white'
  }
});

//将全局state绑定到组件的props中
function mapStateToProps(state) {
  return { 
    currentUnit:state.mainScreenRedux.bwmain.currentUnit,
    currentAddr:state.mainScreenRedux.bwmain.currentAddr
  }
}
//绑定一个方法到props中
function mapDispatchToProps(dispatch) {
  return { 
    mapactions: bindActionCreators(mainScreenActions, dispatch) 
  }
}
//将全局的state绑定到组件中
export default connect(mapStateToProps,mapDispatchToProps)(topbar);